import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import type { _RouteRecordBase } from 'vue-router';
import BasicLayout from '@/layouts/BasicLayout.vue';
import EmptyLayout from '@/layouts/EmptyLayout.vue';
import { Modal } from 'ant-design-vue';

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'index',
    redirect:"/login",
    meta: { title: 'Home' },
    component: BasicLayout,
    children: [
      {
        path: '/user',
        name: 'user',
        meta: { title: '员工管理' },
        component: () => import('@/pages/user/index.vue'),
      },
      {
        path: '/store',
        name: 'store',
        meta: { title: '门店管理' },
        component: () => import('@/pages/store/index.vue'),
      },
      {
        path: '/goods',
        name: 'goods',
        meta: { title: '商品管理' },
        component: () => import('@/pages/goods/index.vue'),
      },
      {
        path: '/packageGroup',
        name: 'packageGroup',
        meta: { title: '套餐组合' },
        component: () => import('@/pages/packageGroup/index.vue'),
      },
      {
        path: '/goodsCategory',
        name: 'goodsCategory',
        meta: { title: '商品品类' },
        component: () => import('@/pages/goodsCategory/index.vue'),
      },
      {
        path: '/coupon',
        name: 'coupon',
        meta: { title: '优惠券管理[开发中]' },
        component: () => import('@/pages/coupon/index.vue'),
      },
      {
        path: '/reservation',
        name: 'reservation',
        meta: { title: '预约管理[开发中]' },
        component: () => import('@/pages/reservation/index.vue'),
      },
      {
        path: '/promoType',
        name: 'promoType',
        meta: { title: '促销类型[开发中]' },
        component: () => import('@/pages/promoType/index.vue'),
      },
      {
        path: '/planScheme',
        name: 'planScheme',
        meta: { title: '促销方案[开发中]' },
        component: () => import('@/pages/planScheme/index.vue'),
      },
    
      {
        path: '/carousel',
        name: 'carousel',
        meta: { title: '轮播图' },
        component: () => import('@/pages/carousel/index.vue'),
      },
      {
        path: '/cashier',
        name: 'cashier',
        meta: { title: '收银台' },
        component: () => import('@/pages/cashier/index.vue'),
      },
      {
        path: '/orders',
        name: 'orders',
        meta: { title: '订单记录' },
        component: () => import('@/pages/orders/index.vue'),
      },
    
      {
        path: '/orderRcord',
        name: 'orderRcord',
        meta: { title: '核销记录' },
        component: () => import('@/pages/orderRcord/index.vue'),
      },
      {
        path: '/wxUser',
        name: 'wxUser',
        meta: { title: '客户管理' },
        component: () => import('@/pages/wxUser/index.vue'),
      },
      {
        path: '/activityPage',
        name: 'activityPage',
        meta: { title: '活动页' },
        component: () => import('@/pages/activityPage/index.vue'),
      },
      {
        path: '/permission',
        name: 'permission',
        meta: { title: '权限列表' },
        component: () => import('@/pages/permission/index.vue'),
      },
      {
        path: '/role',
        name: 'role',
        meta: { title: '角色管理' },
        component: () => import('@/pages/role/index.vue'),
      },
      {
        path: '/history',
        name: 'history',
        meta: { title: '登录记录' },
        component: () => import('@/pages/history/index.vue'),
      },
      {
        path: '/404',
        name: '404',
        hidden:true,
        meta: { title: '404'},
        component: () => import('@/pages/404/index.vue'),
      }
    ],
  },
  {
    path: '/login',
    name: 'login',
    meta: { title: 'Login' },
    component: ()=>import("@/pages/login/index.vue")
  }
];

const router = createRouter({
  history: createWebHashHistory('/'),
  routes,
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { top: 0 };
  },
});

router?.beforeEach((to, from, next) => {
  Modal.destroyAll();
  next();
});

export default router;
